package com.mohan.common;

import java.io.InputStreamReader;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;

public class HttpsReq {
	@SuppressWarnings("finally")
	public static String httpsGet(String code){
		String rep = "";
		try {
			String url = "https://api.weixin.qq.com/sns/jscode2session?" + 
					"appid=" + ConfigInfo.appid +  
					"&secret=" + ConfigInfo.appsecret +
					"&js_code=" + code +
					"&grant_type=authorization_code";
			URL reqURL = new URL(url); //创建URL对象
			HttpsURLConnection httpsConn = (HttpsURLConnection)reqURL.openConnection();
			//取得该连接的输入流，以读取响应内容 
			InputStreamReader insr = new InputStreamReader(httpsConn.getInputStream());

			//读取服务器的响应内容并显示
			int respInt = insr.read();
			while( respInt != -1){
				//System.out.print((char)respInt);
				rep = rep + (char)respInt;
				respInt = insr.read();
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally {
			return rep;
		}	
	}
}
